package net.itren.jetpackdemo.ui

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import android.widget.Toast
import androidx.lifecycle.*
import kotlinx.android.synthetic.main.activity_main.*
import net.itren.jetpackdemo.R
import net.itren.jetpackdemo.model.MainModel
import net.itren.jetpackdemo.observer.MyObserver
import net.itren.jetpackdemo.utils.Utils

class MainActivity : AppCompatActivity(), LifecycleOwner {
    private lateinit var lifecycleRegistry: LifecycleRegistry
    lateinit var mActivity: MainActivity;
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val textView = findViewById<TextView>(R.id.name_text)
        textView.text = "测试"
        name_text.text = "测试二"
        val model = MainModel()
        model.getMyString().observe(this, Observer<String> { users ->
            textView.text = users
        })
        mActivity = this;
        textView.setOnClickListener {

            it.id;
            Toast.makeText(mActivity, "te", Toast.LENGTH_LONG).show();
            model.setMyString(Utils.getName());
            Utils.showToast("是生命的召唤");
        }

        initent.setOnClickListener {
            val intent2 = Intent()
            intent2.setClass(this, TwoActivity::class.java)
            startActivity(intent2)
            finish()
        }
        Log.e(this.javaClass.name, "页面启动")
        lifecycle.addObserver(MyObserver());
    }


    private fun initModel() {
        TODO("Not yet implemented")

    }

    override fun onStart() {
        super.onStart()
        Log.e(this.javaClass.name, "onStart")

    }

    override fun onResume() {
        super.onResume()
        Log.e(this.javaClass.name, "onResume")

    }

    override fun onPause() {
        super.onPause()
        Log.e(this.javaClass.name, "onPause")

    }

    override fun onStop() {
        super.onStop()
        Log.e(this.javaClass.name, "onStop")

    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e(this.javaClass.name, "onDestroy")


    }


}